//
//  ViewController.m
//  10801A
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property(nonatomic,strong)NSArray *left;
@property(nonatomic,strong)NSArray *right;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.pickview.dataSource = self;
    self.pickview.delegate = self;
    self.left=@[@"火鸡",@"花生酱",@"金枪鱼沙拉",@"烤牛肉"@"蔬菜"];
    self.right=@[@"白面包",@"粗面粉面包",@"黑麦面包",@"酸面包"@"天然有机谷"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)press:(id)sender
{
    int sel1 = [self.pickview selectedRowInComponent:0];
    int sel2 = [self.pickview selectedRowInComponent:1];
    NSString *s=[NSString stringWithFormat:@"我今天吃了%@%@",self.left[sel1],self.right[sel2]];
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"吃了" message:s delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
    [alert show];
    
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.left.count;
    }
    else
    {
        return self.right.count;
    }
}
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.left[row];
    }
    else
    {
        return self.right[row];
    }
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(component == 0)
    {
        NSLog(@"当前你选择了%@",self.left[row]);
    }
    else
    {
        NSLog(@"当前你选择了%@",self.right[row]);    }
}

@end
